using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_Client_ContacterManage : Admin, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected DropDownList ddl_ClientType;
	protected TextBox txtSearchClientName;
	protected TextBox txtSearchTrueName;
	protected Button SeachBut;
	protected GridView gvContacterManage;
	protected UpdatePanel UpdatePanel1;
	protected Literal ltrPagePanel;
	protected Panel pnlManage;
	protected Label lblClient;
	protected Label Label1;
	protected Label lblTrueName;
	protected Label lblTitle;
	protected Label lblDepartment;
	protected Label lblPosition;
	protected Label lblOperation;
	protected Label lblCountry;
	protected Label lblProvinceCity;
	protected Label lblAddress;
	protected Label lblZipCode;
	protected Label lblOfficePhone;
	protected Label lblHomePhone;
	protected Label lblMobile;
	protected Label lblFax;
	protected Label lblHomepage;
	protected Label lblEmail;
	protected Label lblQQ;
	protected Label lblMSN;
	protected Label lblYahoo;
	protected Label lblUC;
	protected Label lblBirthday;
	protected Label lblIDCard;
	protected Label lblNativePlace;
	protected Label lblNation;
	protected Label lblSex;
	protected Label lblMarriage;
	protected Label lblEducation;
	protected Label lblGraduateFrom;
	protected Label lblInterestsOfLife;
	protected Label lblInterestsOfCulture;
	protected Label lblInterestsOfAmusement;
	protected Label lblInterestsOfSport;
	protected Label lblInterestsOfOther;
	protected Label lblIncome;
	protected Label lblFamily;
	protected HtmlInputButton Button1;
	protected Panel pnlCheckInfo;
	private string linkHead = "";
	private string beforeUrl = "Admin_Client_ContacterManage.aspx?MenuID=2&MenuName=客户管理&FileName=联系人管理";
	private string actionTab = "";
	private int contacID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public string ActionTab
	{
		get
		{
			if (base.Request.QueryString["action"] != null)
			{
				this.actionTab = base.Request.QueryString["action"].Trim();
			}
			else
			{
				this.actionTab = "";
			}
			return this.actionTab;
		}
		set
		{
			this.actionTab = value;
		}
	}
	public int ContacID
	{
		get
		{
			if (base.Request.QueryString["contacterID"] != null)
			{
				this.contacID = Convert.ToInt32(base.Request.QueryString["contacterID"].Trim());
			}
			return this.contacID;
		}
		set
		{
			this.contacID = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(44))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_Client_ContacterManage");
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(this.ActionTab);
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (DisplayName == "checkinfo")
			{
				this.pnlManage.Visible = false;
				this.pnlCheckInfo.Visible = true;
				if (this.ContacID > 0)
				{
					this.InitPage();
				}
				return;
			}
		}
		this.pnlManage.Visible = true;
		this.pnlCheckInfo.Visible = false;
		this.ddl_ClientType.bindDataToDropDownList("HL_Client", "ClientType", false, false);
		this.BindClientContacter();
	}
	protected void InitPage()
	{
		HoWave.Data.Model.ClientContacter model = HoWave.Data.Bll.ClientContacter.instance.GetModel(this.ContacID);
		if (model != null)
		{
			HoWave.Data.Model.Client model2 = HoWave.Data.Bll.Client.instance.GetModel((int)Convert.ToInt16(model.ClientID));
			if (model2 != null)
			{
				this.lblClient.Text = model2.ClientName;
			}
			this.lblTrueName.Text = model.TrueName;
			this.lblTitle.Text = model.Title;
			this.lblDepartment.Text = model.Department;
			this.lblPosition.Text = model.Position;
			this.lblOperation.Text = model.Operation;
			this.lblCountry.Text = model.Company;
			this.lblProvinceCity.Text = string.Concat(new string[]
			{
				model.Province,
				"&nbsp;",
				model.City,
				"&nbsp;",
				model.Districts
			});
			this.lblAddress.Text = model.Address;
			this.lblZipCode.Text = model.ZipCode;
			this.lblOfficePhone.Text = model.OfficePhone;
			this.lblHomePhone.Text = model.HomePhone;
			this.lblMobile.Text = model.Mobile;
			this.lblFax.Text = model.Fax;
			this.lblHomepage.Text = model.Homepage;
			this.lblEmail.Text = model.Email;
			this.lblQQ.Text = model.QQ;
			this.lblMSN.Text = model.MSN;
			this.lblYahoo.Text = model.Yahoo;
			this.lblUC.Text = model.UC;
			this.lblBirthday.Text = "";
			if (model.Birthday.HasValue)
			{
				this.lblBirthday.Text = model.Birthday.ToString();
			}
			this.lblBirthday.Text = model.Birthday.ToString();
			this.lblIDCard.Text = model.IDCard;
			this.lblNativePlace.Text = model.NativePlace;
			this.lblNation.Text = model.Nation;
			this.lblSex.Text = this.GetDictionaryTitle(model.Sex.ToString());
			this.lblMarriage.Text = this.GetDictionaryTitle(model.Marriage.ToString());
			this.lblEducation.Text = this.GetDictionaryTitle(model.Education);
			this.lblGraduateFrom.Text = model.GraduateFrom;
			this.lblInterestsOfLife.Text = model.InterestsOfLife;
			this.lblInterestsOfCulture.Text = model.InterestsOfCulture;
			this.lblInterestsOfAmusement.Text = model.InterestsOfAmusement;
			this.lblInterestsOfSport.Text = model.InterestsOfSport;
			this.lblInterestsOfOther.Text = model.InterestsOfOther;
			this.lblIncome.Text = this.GetDictionaryTitle(model.Income);
			this.lblFamily.Text = model.Family;
		}
	}
	protected string GetDictionaryTitle(string fieldValue)
	{
		string result = "";
		HoWave.Data.Bll.Dictionary dictionary = new HoWave.Data.Bll.Dictionary();
		HoWave.Data.Model.Dictionary dictionary2 = dictionary.GetDictionary(fieldValue);
		if (dictionary2 != null)
		{
			result = dictionary2.FieldText;
		}
		return result;
	}
	protected void BindClientContacter()
	{
		string query = this.GetQuery();
		int num = this.gvContacterManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HL_Client as c,HL_ClientContacter as cc where cc.ClientID=c.ClientID  ";
		int pageSize = this.gvContacterManage.PageSize;
		int listCount = HoWave.Data.Bll.ClientContacter.instance.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "(select UserName from HL_User where UserID=c.Owner) as ownerName,c.GroupID,c.ClientType,c.ClientName,ROW_NUMBER() OVER (order by cc.ContacterID desc) as row,cc.* ";
		string strSQL = "select " + str + text + query;
		DataTable contacterListByPage = HoWave.Data.Bll.ClientContacter.instance.GetContacterListByPage(strSQL, "row", startIndex, endIndex);
		this.gvContacterManage.DataSource = contacterListByPage;
		this.gvContacterManage.DataBind();
		CurrPageLinks currPageLinks = new CurrPageLinks();
		string url = this.beforeUrl + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条记录", url);
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ClientType");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddl_ClientType.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddl_ClientType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and ClientType='" + text2 + "'";
			this.linkHead = this.linkHead + "&ClientType=" + text2;
		}
		string text3 = Fetch.Get("KeHuName");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchClientName.Text = text3;
		}
		else
		{
			text3 = this.txtSearchClientName.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and c.ClientName like '%" + text3 + "%'";
			this.linkHead = this.linkHead + "&KeHuName=" + text3;
		}
		string text4 = Fetch.Get("TrueName");
		if (!string.IsNullOrEmpty(text4))
		{
			this.txtSearchTrueName.Text = text4;
		}
		else
		{
			text4 = this.txtSearchTrueName.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and cc.TrueName like '%" + text4 + "%'";
			this.linkHead = this.linkHead + "&TrueName=" + text4;
		}
		return text;
	}
	protected string GetContacPhone(string officePhone, string homephome, string mobile)
	{
		string text = "";
		if (!string.IsNullOrEmpty(officePhone))
		{
			text = text + "办公：" + officePhone + "<br>";
		}
		if (!string.IsNullOrEmpty(homephome))
		{
			text = text + "住宅：" + homephome + "<br>";
		}
		if (!string.IsNullOrEmpty(mobile))
		{
			text = text + "手机：" + mobile;
		}
		return text;
	}
	protected void gvContacterManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvContacterManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvContacterManage.PageIndex = e.NewPageIndex;
		this.BindClientContacter();
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string commandName = e.CommandName;
		if (commandName == "CheckInfo")
		{
			string text = e.CommandArgument.ToString();
			if (!string.IsNullOrEmpty(text))
			{
				base.Response.Redirect(this.beforeUrl + "&action=checkinfo&contacterID=" + text);
			}
		}
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindClientContacter();
	}
}
